/**
 * @author： pang-yun
 * @date： 2021-11-01 14:23
 * 功能目的 ：用于
 */

public class Guard {
    public static void main(String[] args) {

    }
}

class G {
    private Object response;

    public Object getResponse(long timeout) {
        synchronized (this) {
            long begin = System.currentTimeMillis();
            long passTime = 0;

            while (response == null) {
                if (passTime > timeout) {
                    break;
                }
                try {
                    this.wait(timeout - passTime);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                passTime = System.currentTimeMillis() - begin;
            }
        }
        return response;
    }


    public void complete(Object response) {
        synchronized (this){
            this.response = response;
            this.notifyAll();

        }
    }
}
